#pragma once
#include "OCR.h"
#include "DetectorRegiones.h"
#include "utils.h"

namespace Thesis_3 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for ReconocimientoForm
	/// </summary>
	public ref class ReconocimientoForm : public System::Windows::Forms::Form
	{
	public:
		ReconocimientoForm(void)
		{

			numerosPlaca = new vector<Mat>;
			histogramasHoriz = new vector<Mat>;
			histogramasVert = new vector<Mat>;
			placasDivididas = new vector<Mat>;
			divisioneshorizontales = new vector<int*>;
			ocrModule = new OCR();
			ocrModule->init();
			nPlacasHist = 0;
			nPlacasCaracteres = 0;
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}
		vector<Mat> *numerosPlaca;
		vector<Mat> *histogramasHoriz;
		vector<Mat> *histogramasVert;
		vector<Mat> *placasDivididas;
		vector<int*> *divisioneshorizontales;
		DetectorRegiones * detector;
		int nPlacasHist;
		int nPlacasCaracteres;
	private: System::Windows::Forms::PictureBox^  histogramaIzquierdo;
	private: System::Windows::Forms::PictureBox^  imagenDerecha;
	private: System::Windows::Forms::PictureBox^  histogramaInferior;
	private: System::Windows::Forms::GroupBox^  grupoNavegacionCaracteres;

	private: System::Windows::Forms::CheckBox^  checkPlacaCaracteres;
	private: System::Windows::Forms::Button^  botonPlacaCaracteresAnterior;




	private: System::Windows::Forms::Button^  botonPlacaCaracteresSiguiente;


	private: System::Windows::Forms::Label^  labelPlacaCaracteres;
	private: System::Windows::Forms::ContextMenuStrip^  guardarMenuStrip;

	private: System::Windows::Forms::ToolStripMenuItem^  guardarToolStripMenuItem;
	private: System::Windows::Forms::MenuStrip^  menuStrip1;
	private: System::Windows::Forms::ToolStripMenuItem^  guardarImagenToolStripMenuItem;

	public: 
		OCR* ocrModule;
	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~ReconocimientoForm()
		{
			if (components)
			{
				delete components;
			}
			delete numerosPlaca;
			delete histogramasHoriz;
			delete histogramasVert;
			delete placasDivididas;
			delete [] divisioneshorizontales;
			delete ocrModule;
		}
	private: System::Windows::Forms::PictureBox^  imagenReconocimiento;
	private: System::Windows::Forms::Button^  botonReconocer;
	private: System::Windows::Forms::GroupBox^  grupoNavegacionPlaca;
	private: System::Windows::Forms::CheckBox^  checkPlacaHistograma;
	private: System::Windows::Forms::Button^  botonPlacaHistogramaAnterior;
	private: System::Windows::Forms::Button^  botonPlacaHistogramaSiguiente;





	private: System::Windows::Forms::Label^  labelPlacaHistograma;
	private: System::ComponentModel::IContainer^  components;

	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->imagenReconocimiento = (gcnew System::Windows::Forms::PictureBox());
			this->botonReconocer = (gcnew System::Windows::Forms::Button());
			this->grupoNavegacionPlaca = (gcnew System::Windows::Forms::GroupBox());
			this->checkPlacaHistograma = (gcnew System::Windows::Forms::CheckBox());
			this->botonPlacaHistogramaAnterior = (gcnew System::Windows::Forms::Button());
			this->botonPlacaHistogramaSiguiente = (gcnew System::Windows::Forms::Button());
			this->labelPlacaHistograma = (gcnew System::Windows::Forms::Label());
			this->histogramaIzquierdo = (gcnew System::Windows::Forms::PictureBox());
			this->guardarMenuStrip = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
			this->guardarToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->imagenDerecha = (gcnew System::Windows::Forms::PictureBox());
			this->histogramaInferior = (gcnew System::Windows::Forms::PictureBox());
			this->grupoNavegacionCaracteres = (gcnew System::Windows::Forms::GroupBox());
			this->checkPlacaCaracteres = (gcnew System::Windows::Forms::CheckBox());
			this->botonPlacaCaracteresAnterior = (gcnew System::Windows::Forms::Button());
			this->botonPlacaCaracteresSiguiente = (gcnew System::Windows::Forms::Button());
			this->labelPlacaCaracteres = (gcnew System::Windows::Forms::Label());
			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
			this->guardarImagenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imagenReconocimiento))->BeginInit();
			this->grupoNavegacionPlaca->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->histogramaIzquierdo))->BeginInit();
			this->guardarMenuStrip->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imagenDerecha))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->histogramaInferior))->BeginInit();
			this->grupoNavegacionCaracteres->SuspendLayout();
			this->menuStrip1->SuspendLayout();
			this->SuspendLayout();
			// 
			// imagenReconocimiento
			// 
			this->imagenReconocimiento->Location = System::Drawing::Point(276, 38);
			this->imagenReconocimiento->Name = L"imagenReconocimiento";
			this->imagenReconocimiento->Size = System::Drawing::Size(980, 703);
			this->imagenReconocimiento->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
			this->imagenReconocimiento->TabIndex = 2;
			this->imagenReconocimiento->TabStop = false;
			this->imagenReconocimiento->Visible = false;
			// 
			// botonReconocer
			// 
			this->botonReconocer->Location = System::Drawing::Point(12, 38);
			this->botonReconocer->Name = L"botonReconocer";
			this->botonReconocer->Size = System::Drawing::Size(241, 49);
			this->botonReconocer->TabIndex = 8;
			this->botonReconocer->Text = L"Iniciar";
			this->botonReconocer->UseVisualStyleBackColor = true;
			this->botonReconocer->Click += gcnew System::EventHandler(this, &ReconocimientoForm::botonReconocer_Click);
			// 
			// grupoNavegacionPlaca
			// 
			this->grupoNavegacionPlaca->Controls->Add(this->checkPlacaHistograma);
			this->grupoNavegacionPlaca->Controls->Add(this->botonPlacaHistogramaAnterior);
			this->grupoNavegacionPlaca->Controls->Add(this->botonPlacaHistogramaSiguiente);
			this->grupoNavegacionPlaca->Controls->Add(this->labelPlacaHistograma);
			this->grupoNavegacionPlaca->Location = System::Drawing::Point(12, 116);
			this->grupoNavegacionPlaca->Name = L"grupoNavegacionPlaca";
			this->grupoNavegacionPlaca->Size = System::Drawing::Size(241, 172);
			this->grupoNavegacionPlaca->TabIndex = 9;
			this->grupoNavegacionPlaca->TabStop = false;
			this->grupoNavegacionPlaca->Text = L"Placas con histograma";
			// 
			// checkPlacaHistograma
			// 
			this->checkPlacaHistograma->AutoSize = true;
			this->checkPlacaHistograma->Enabled = false;
			this->checkPlacaHistograma->Location = System::Drawing::Point(6, 39);
			this->checkPlacaHistograma->Name = L"checkPlacaHistograma";
			this->checkPlacaHistograma->Size = System::Drawing::Size(205, 21);
			this->checkPlacaHistograma->TabIndex = 4;
			this->checkPlacaHistograma->Text = L"Ver placas con histogramas";
			this->checkPlacaHistograma->UseVisualStyleBackColor = true;
			this->checkPlacaHistograma->Visible = false;
			this->checkPlacaHistograma->CheckedChanged += gcnew System::EventHandler(this, &ReconocimientoForm::checkPlacaHistograma_CheckedChanged);
			// 
			// botonPlacaHistogramaAnterior
			// 
			this->botonPlacaHistogramaAnterior->Enabled = false;
			this->botonPlacaHistogramaAnterior->Location = System::Drawing::Point(8, 85);
			this->botonPlacaHistogramaAnterior->Name = L"botonPlacaHistogramaAnterior";
			this->botonPlacaHistogramaAnterior->Size = System::Drawing::Size(99, 49);
			this->botonPlacaHistogramaAnterior->TabIndex = 1;
			this->botonPlacaHistogramaAnterior->Text = L"Anterior";
			this->botonPlacaHistogramaAnterior->UseVisualStyleBackColor = true;
			this->botonPlacaHistogramaAnterior->Click += gcnew System::EventHandler(this, &ReconocimientoForm::botonPlacaHistogramaAnterior_Click);
			// 
			// botonPlacaHistogramaSiguiente
			// 
			this->botonPlacaHistogramaSiguiente->Enabled = false;
			this->botonPlacaHistogramaSiguiente->Location = System::Drawing::Point(126, 85);
			this->botonPlacaHistogramaSiguiente->Name = L"botonPlacaHistogramaSiguiente";
			this->botonPlacaHistogramaSiguiente->Size = System::Drawing::Size(99, 49);
			this->botonPlacaHistogramaSiguiente->TabIndex = 2;
			this->botonPlacaHistogramaSiguiente->Text = L"Siguiente";
			this->botonPlacaHistogramaSiguiente->UseVisualStyleBackColor = true;
			this->botonPlacaHistogramaSiguiente->Click += gcnew System::EventHandler(this, &ReconocimientoForm::botonPlacaHistogramaSiguiente_Click);
			// 
			// labelPlacaHistograma
			// 
			this->labelPlacaHistograma->AutoSize = true;
			this->labelPlacaHistograma->Location = System::Drawing::Point(6, 40);
			this->labelPlacaHistograma->Name = L"labelPlacaHistograma";
			this->labelPlacaHistograma->Size = System::Drawing::Size(0, 17);
			this->labelPlacaHistograma->TabIndex = 3;
			// 
			// histogramaIzquierdo
			// 
			this->histogramaIzquierdo->ContextMenuStrip = this->guardarMenuStrip;
			this->histogramaIzquierdo->Location = System::Drawing::Point(276, 38);
			this->histogramaIzquierdo->Name = L"histogramaIzquierdo";
			this->histogramaIzquierdo->Size = System::Drawing::Size(490, 350);
			this->histogramaIzquierdo->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
			this->histogramaIzquierdo->TabIndex = 10;
			this->histogramaIzquierdo->TabStop = false;
			// 
			// guardarMenuStrip
			// 
			this->guardarMenuStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->guardarToolStripMenuItem});
			this->guardarMenuStrip->Name = L"contextMenuStrip1";
			this->guardarMenuStrip->Size = System::Drawing::Size(132, 28);
			// 
			// guardarToolStripMenuItem
			// 
			this->guardarToolStripMenuItem->Name = L"guardarToolStripMenuItem";
			this->guardarToolStripMenuItem->Size = System::Drawing::Size(131, 24);
			this->guardarToolStripMenuItem->Text = L"Guardar";
			this->guardarToolStripMenuItem->Click += gcnew System::EventHandler(this, &ReconocimientoForm::guardarToolStripMenuItem_Click);
			// 
			// imagenDerecha
			// 
			this->imagenDerecha->ContextMenuStrip = this->guardarMenuStrip;
			this->imagenDerecha->Location = System::Drawing::Point(766, 38);
			this->imagenDerecha->Name = L"imagenDerecha";
			this->imagenDerecha->Size = System::Drawing::Size(490, 350);
			this->imagenDerecha->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
			this->imagenDerecha->TabIndex = 11;
			this->imagenDerecha->TabStop = false;
			// 
			// histogramaInferior
			// 
			this->histogramaInferior->ContextMenuStrip = this->guardarMenuStrip;
			this->histogramaInferior->Location = System::Drawing::Point(766, 388);
			this->histogramaInferior->Name = L"histogramaInferior";
			this->histogramaInferior->Size = System::Drawing::Size(490, 353);
			this->histogramaInferior->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
			this->histogramaInferior->TabIndex = 12;
			this->histogramaInferior->TabStop = false;
			// 
			// grupoNavegacionCaracteres
			// 
			this->grupoNavegacionCaracteres->Controls->Add(this->checkPlacaCaracteres);
			this->grupoNavegacionCaracteres->Controls->Add(this->botonPlacaCaracteresAnterior);
			this->grupoNavegacionCaracteres->Controls->Add(this->botonPlacaCaracteresSiguiente);
			this->grupoNavegacionCaracteres->Controls->Add(this->labelPlacaCaracteres);
			this->grupoNavegacionCaracteres->Location = System::Drawing::Point(12, 294);
			this->grupoNavegacionCaracteres->Name = L"grupoNavegacionCaracteres";
			this->grupoNavegacionCaracteres->Size = System::Drawing::Size(241, 172);
			this->grupoNavegacionCaracteres->TabIndex = 10;
			this->grupoNavegacionCaracteres->TabStop = false;
			this->grupoNavegacionCaracteres->Text = L"Caracteres reconocidos";
			// 
			// checkPlacaCaracteres
			// 
			this->checkPlacaCaracteres->AutoSize = true;
			this->checkPlacaCaracteres->Enabled = false;
			this->checkPlacaCaracteres->Location = System::Drawing::Point(9, 39);
			this->checkPlacaCaracteres->Name = L"checkPlacaCaracteres";
			this->checkPlacaCaracteres->Size = System::Drawing::Size(195, 21);
			this->checkPlacaCaracteres->TabIndex = 4;
			this->checkPlacaCaracteres->Text = L"Ver placas con caracteres";
			this->checkPlacaCaracteres->UseVisualStyleBackColor = true;
			this->checkPlacaCaracteres->Visible = false;
			this->checkPlacaCaracteres->CheckedChanged += gcnew System::EventHandler(this, &ReconocimientoForm::checkPlacasCaracteres_CheckedChanged);
			// 
			// botonPlacaCaracteresAnterior
			// 
			this->botonPlacaCaracteresAnterior->Enabled = false;
			this->botonPlacaCaracteresAnterior->Location = System::Drawing::Point(8, 85);
			this->botonPlacaCaracteresAnterior->Name = L"botonPlacaCaracteresAnterior";
			this->botonPlacaCaracteresAnterior->Size = System::Drawing::Size(99, 49);
			this->botonPlacaCaracteresAnterior->TabIndex = 1;
			this->botonPlacaCaracteresAnterior->Text = L"Anterior";
			this->botonPlacaCaracteresAnterior->UseVisualStyleBackColor = true;
			this->botonPlacaCaracteresAnterior->Click += gcnew System::EventHandler(this, &ReconocimientoForm::botonPlacaCaracteresAnterior_Click);
			// 
			// botonPlacaCaracteresSiguiente
			// 
			this->botonPlacaCaracteresSiguiente->Enabled = false;
			this->botonPlacaCaracteresSiguiente->Location = System::Drawing::Point(126, 85);
			this->botonPlacaCaracteresSiguiente->Name = L"botonPlacaCaracteresSiguiente";
			this->botonPlacaCaracteresSiguiente->Size = System::Drawing::Size(99, 49);
			this->botonPlacaCaracteresSiguiente->TabIndex = 2;
			this->botonPlacaCaracteresSiguiente->Text = L"Siguiente";
			this->botonPlacaCaracteresSiguiente->UseVisualStyleBackColor = true;
			this->botonPlacaCaracteresSiguiente->Click += gcnew System::EventHandler(this, &ReconocimientoForm::botonPlacaCaracteresSiguiente_Click);
			// 
			// labelPlacaCaracteres
			// 
			this->labelPlacaCaracteres->AutoSize = true;
			this->labelPlacaCaracteres->Location = System::Drawing::Point(6, 40);
			this->labelPlacaCaracteres->Name = L"labelPlacaCaracteres";
			this->labelPlacaCaracteres->Size = System::Drawing::Size(0, 17);
			this->labelPlacaCaracteres->TabIndex = 3;
			// 
			// menuStrip1
			// 
			this->menuStrip1->Enabled = false;
			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->guardarImagenToolStripMenuItem});
			this->menuStrip1->Location = System::Drawing::Point(0, 0);
			this->menuStrip1->Name = L"menuStrip1";
			this->menuStrip1->Size = System::Drawing::Size(1268, 28);
			this->menuStrip1->TabIndex = 13;
			this->menuStrip1->Text = L"menuStrip1";
			// 
			// guardarImagenToolStripMenuItem
			// 
			this->guardarImagenToolStripMenuItem->Name = L"guardarImagenToolStripMenuItem";
			this->guardarImagenToolStripMenuItem->Size = System::Drawing::Size(128, 24);
			this->guardarImagenToolStripMenuItem->Text = L"Guardar Imagen";
			this->guardarImagenToolStripMenuItem->Click += gcnew System::EventHandler(this, &ReconocimientoForm::guardarImagenToolStripMenuItem_Click);
			// 
			// ReconocimientoForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(1268, 753);
			this->Controls->Add(this->menuStrip1);
			this->Controls->Add(this->grupoNavegacionCaracteres);
			this->Controls->Add(this->histogramaInferior);
			this->Controls->Add(this->imagenDerecha);
			this->Controls->Add(this->histogramaIzquierdo);
			this->Controls->Add(this->botonReconocer);
			this->Controls->Add(this->grupoNavegacionPlaca);
			this->Controls->Add(this->imagenReconocimiento);
			this->Name = L"ReconocimientoForm";
			this->Text = L"Reconocimiento";
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imagenReconocimiento))->EndInit();
			this->grupoNavegacionPlaca->ResumeLayout(false);
			this->grupoNavegacionPlaca->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->histogramaIzquierdo))->EndInit();
			this->guardarMenuStrip->ResumeLayout(false);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imagenDerecha))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->histogramaInferior))->EndInit();
			this->grupoNavegacionCaracteres->ResumeLayout(false);
			this->grupoNavegacionCaracteres->PerformLayout();
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: 
		void actualizarLabelPlacaHistograma(){
			this->labelPlacaHistograma->Text = "Placa "+(nPlacasHist+1)+" de "+placasDivididas->size();
		}
		void actualizarLabelPlacaCaracteres(){
			this->labelPlacaCaracteres->Text = "Placa "+(nPlacasCaracteres+1)+" de "+numerosPlaca->size();
		}
		void init(){
			Mat imagenColor = detector->input_image_color;
			ocrModule->hallarImagenesReconocimiento(imagenColor,*(detector->cornersGlobal),*numerosPlaca,*histogramasHoriz,*histogramasVert,*placasDivididas,*divisioneshorizontales);
			for (int i=0; i<placasDivididas->size(); i++){
				cvtColor(histogramasHoriz->at(i),(*histogramasHoriz)[i],CV_GRAY2BGRA);
				cvtColor(histogramasVert->at(i),(*histogramasVert)[i],CV_GRAY2BGRA);
				cvtColor(placasDivididas->at(i),(*placasDivididas)[i],CV_BGR2BGRA);
			}
			for (int i=0; i<numerosPlaca->size(); i++){
				ocrModule->detect(numerosPlaca->at(i),(*numerosPlaca)[i],divisioneshorizontales->at(i));
				cvtColor(numerosPlaca->at(i),(*numerosPlaca)[i],CV_BGR2BGRA);
			}
			if (placasDivididas->size() > 0){
				dibujarImagen(histogramaIzquierdo,histogramasVert->at(0));
				dibujarImagen(histogramaInferior,histogramasHoriz->at(0));
				dibujarImagen(imagenDerecha,placasDivididas->at(0));
				if (placasDivididas->size() > 1)
					this->botonPlacaHistogramaSiguiente->Enabled = true;
				actualizarLabelPlacaHistograma();
			}else{
				this->labelPlacaHistograma->Text = "No se encontraron placas";
			}
			if (numerosPlaca->size() > 0){
				dibujarImagen(imagenReconocimiento,numerosPlaca->at(0));
				this->checkPlacaCaracteres->Enabled = true;
				this->checkPlacaCaracteres->Visible = true;
				this->menuStrip1->Enabled = true;
			}else{
				this->labelPlacaCaracteres->Text = "No se encontraron placas que satisfagan la condicion de cortes horizontales";
			}
		}
		System::Void botonReconocer_Click(System::Object^  sender, System::EventArgs^  e) {
			this->init();
			this->botonReconocer->Enabled = false;
		}
	private: 
		System::Void botonPlacaHistogramaAnterior_Click(System::Object^  sender, System::EventArgs^  e) {
			nPlacasHist--;
			if (nPlacasHist == 0)
				this->botonPlacaHistogramaAnterior->Enabled = false;
			else 
				this->botonPlacaHistogramaAnterior->Enabled = true;
			this->botonPlacaHistogramaSiguiente->Enabled = true;
			dibujarImagen(histogramaIzquierdo,histogramasVert->at(nPlacasHist));
			dibujarImagen(histogramaInferior,histogramasHoriz->at(nPlacasHist));
			dibujarImagen(imagenDerecha,placasDivididas->at(nPlacasHist));
			actualizarLabelPlacaHistograma();
		}
		System::Void botonPlacaHistogramaSiguiente_Click(System::Object^  sender, System::EventArgs^  e) {
			nPlacasHist++;
			if (nPlacasHist == placasDivididas->size()-1)
				this->botonPlacaHistogramaSiguiente->Enabled = false;
			else 
				this->botonPlacaHistogramaSiguiente->Enabled = true;
			this->botonPlacaHistogramaAnterior->Enabled = true;
			dibujarImagen(histogramaIzquierdo,histogramasVert->at(nPlacasHist));
			dibujarImagen(histogramaInferior,histogramasHoriz->at(nPlacasHist));
			dibujarImagen(imagenDerecha,placasDivididas->at(nPlacasHist));
			actualizarLabelPlacaHistograma();
		}
	private: 
		System::Void checkPlacaHistograma_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
			if (this->checkPlacaHistograma->Checked == true){
				this->checkPlacaHistograma->Enabled = false;
				this->checkPlacaHistograma->Visible = false;
				this->labelPlacaHistograma->Visible = true;

				this->checkPlacaCaracteres->Enabled = true;
				this->checkPlacaCaracteres->Visible = true;
				this->checkPlacaCaracteres->Checked = false;
				this->labelPlacaCaracteres->Visible = false;
				this->botonPlacaCaracteresAnterior->Enabled = false;
				this->botonPlacaCaracteresSiguiente->Enabled = false;

				this->histogramaIzquierdo->Visible = true;
				this->histogramaInferior->Visible = true;
				this->imagenDerecha->Visible = true;
				this->imagenReconocimiento->Visible = false;
				if (this->nPlacasHist > 0)
					this->botonPlacaHistogramaAnterior->Enabled = true;
				if (this->nPlacasHist < this->placasDivididas->size()-1)
					this->botonPlacaHistogramaSiguiente->Enabled = true;
				this->menuStrip1->Enabled = false;
				this->menuStrip1->Text = "Click derecho en la imagen para guardar";

				actualizarLabelPlacaHistograma();
			}
		}
		System::Void checkPlacasCaracteres_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
			if (this->checkPlacaCaracteres->Checked == true){
				this->checkPlacaCaracteres->Enabled = false;
				this->checkPlacaCaracteres->Visible = false;
				this->labelPlacaCaracteres->Visible = true;

				this->checkPlacaHistograma->Enabled = true;
				this->checkPlacaHistograma->Visible = true;
				this->checkPlacaHistograma->Checked = false;
				this->labelPlacaHistograma->Visible = false;
				this->botonPlacaHistogramaAnterior->Enabled = false;
				this->botonPlacaHistogramaSiguiente->Enabled = false;

				this->histogramaIzquierdo->Visible = false;
				this->histogramaInferior->Visible = false;
				this->imagenDerecha->Visible = false;
				this->imagenReconocimiento->Visible = true;
				if (this->nPlacasCaracteres > 0)
					this->botonPlacaCaracteresAnterior->Enabled = true;
				if (this->nPlacasCaracteres < this->numerosPlaca->size()-1)
					this->botonPlacaCaracteresSiguiente->Enabled = true;
				this->menuStrip1->Enabled = true;
				this->menuStrip1->Text = "Guardar Imagen";

				actualizarLabelPlacaCaracteres();
			}
		}
		System::Void botonPlacaCaracteresAnterior_Click(System::Object^  sender, System::EventArgs^  e) {
			nPlacasCaracteres--;
			if (nPlacasCaracteres == 0)
				this->botonPlacaCaracteresAnterior->Enabled = false;
			else 
				this->botonPlacaCaracteresAnterior->Enabled = true;
			this->botonPlacaCaracteresSiguiente->Enabled = true;
			dibujarImagen(imagenReconocimiento,numerosPlaca->at(nPlacasCaracteres));
			actualizarLabelPlacaCaracteres();
		}
		System::Void botonPlacaCaracteresSiguiente_Click(System::Object^  sender, System::EventArgs^  e) {
			nPlacasCaracteres++;
			if (nPlacasCaracteres == numerosPlaca->size()-1)
				this->botonPlacaCaracteresSiguiente->Enabled = false;
			else 
				this->botonPlacaCaracteresSiguiente->Enabled = true;
			this->botonPlacaCaracteresAnterior->Enabled = true;
			dibujarImagen(imagenReconocimiento,numerosPlaca->at(nPlacasCaracteres));
			actualizarLabelPlacaCaracteres();
		}
	private: System::Void guardarToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
				 ToolStripMenuItem^ item = (ToolStripMenuItem^)sender;
				 System::Windows::Forms::ContextMenuStrip^ menu = (System::Windows::Forms::ContextMenuStrip^)item->Owner;
				 PictureBox^ pb = (PictureBox^)menu->SourceControl;

				 SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
				 saveFileDialog1->InitialDirectory = "\\";
				 saveFileDialog1->RestoreDirectory = true;
				 saveFileDialog1->FileName = pb->Name+".jpg";
				 saveFileDialog1->Filter = "JPG files (*.jpg)|*.jpg|PNG files (*.png)|*.png";
				 if ( saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
				 {
					 pb->Image->Save(saveFileDialog1->FileName);
				 }
			 }
	private: System::Void guardarImagenToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
				 SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
				 saveFileDialog1->InitialDirectory = "\\";
				 saveFileDialog1->RestoreDirectory = true;
				 saveFileDialog1->FileName = "imagen_reconocimiento.jpg";
				 saveFileDialog1->Filter = "JPG files (*.jpg)|*.jpg|PNG files (*.png)|*.png";
				 if ( saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
				 {
					 this->imagenReconocimiento->Image->Save(saveFileDialog1->FileName);
				 }
			 }
	};
}
